<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录</title>
#include("_common/head.html")
<!-- 样 式 文 件 -->
<link rel="stylesheet" href="#(ctxPath)/pear/admin/css/other/login.css" />
<link rel="icon" type="image/x-icon" href="#(ctxPath)#site('icon')">
<link rel="shortcut icon" type="image/x-icon" href="#(ctxPath)#site('icon')">
</head>
<!-- 代 码 结 构 -->
<body background="#(ctxPath)/pear/admin/images/background.svg"
	style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);" lay-filter="login-form">
		<div class="layui-form-item">
			<img class="logo" src="#(ctxPath)/pear/admin/images/logo.png" />
			<div class="title">#site("name")<br>
                #(jbsaRegionName)
                <span style="font-weight: 600; font-size: 24px; color: red;">
                #if(jbsaAppMode == "dev")（开发环境）#end
                #if(jbsaAppMode == "test")（测试环境）#end
                #if(jbsaAppMode == "perf")（性能环境）#end
                </span>
            </div>
			<div class="desc"></div>
		</div>
		<div class="layui-form-item">
			<input name="account" placeholder="账 户 :" lay-verify="required" class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input name="password" type="password" placeholder="密 码 :" lay-verify="required" autocomplete="off" class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input name="captcha" placeholder="验证码 : " autocomplete="off" lay-verify="required" class="code layui-input layui-input-inline" />
			<a href="javascript:void(0);">
                <img src="#(ctxPath)/admin/captcha" onclick="this.src='#(ctxPath)/admin/captcha?t='+(new Date()).getTime();" class="captcha-image" />
			</a>
		</div>
		<div class="layui-form-item">
			<button id="login-button" type="button" class="pear-btn pear-btn-success login" lay-submit lay-filter="login">登 入</button>
		</div>
	</form>
<!-- 资 源 引 入 -->
#include("_common/foot.html")
<script>
layui.use(['form', 'button', 'popup'], function() {
    var $ = layui.jquery;
    var form = layui.form;
    var button = layui.button;
    var popup = layui.popup;
    
    var MODULE_PATH = "#(ctxPath)/admin/";
    
    /*
     * 登录
     */
    form.on('submit(login)', function(data) {
        $.ajax({
            url: MODULE_PATH + "doLogin",
            dataType: 'json',
            data: data.field,
            type: 'post',
            beforeSend : function(){layer.load(1);}, // 防止重复操作
            complete : function(){layer.closeAll('loading');}, //解除防重复操作
            success: function(result) {
                if (result.success) {
                    // 动画
                    popup.success("登录成功", function() {
                        location.href = MODULE_PATH;
                    });
                } else {
                    form.val("login-form", {"captcha": ""});
                    popup.failure(result.message, function() {
                        window.refreshCaptcha();
                        return;
                    });
                }
            },
            error : function (e) { // Ajax调用失败
                layer.alert("操作失败：" + e.responseText, {icon: 2});
            }
        })
        
        window.refreshCaptcha = function() {
            $(".captcha-image").click();
        }
        
        return false;
    });
    
    /*
     * 监听验证码输入框的回车事件
     */
    $("[name='captcha']").on('keydown', function (event) {
        if (event.keyCode == 13) {
            $("#login-button").click();
        }
    });
})
</script>
</body>
</html>
